<?php
var_dump($_POST);
//用post函数接收表单传来的值
$studentName = $_POST['student_name'] ?? '';
$studentSex = $_POST['student_sex'] ?? '';
$studentBirthday = $_POST['student_birthday'] ?? '';
$studentAddress = $_POST['student_address'] ?? '';

//连接数据库
$dsn = "sqlsrv:Server=localhost;Database=Student";
$db = new PDO($dsn, "sa", "123456");
//将添加的学生信息存储到数据库中

$sql = "insert into Student (StudentName, StudentSex, StudentBirth, StudentAddress) 
	values ('{$studentName}', '{$studentSex}', '{$studentBirthday}', '{$studentAddress}');";
//布尔类型的变量
$result = $db->exec($sql);
//判断是否正确
if ($result) {
    echo '增加学生成功，前往<a href="student_list.php">列表页</a>';
} else {
    echo '添加失败';
}
